var figures = {
   O : {
      1: [[1,1], 
          [1,1]],
      length: 1
   },
   S : {
      1: [[0,1,1],
          [1,1,0]],
      2: [[1,0],
          [1,1],
          [0,1]],
      length: 2
   },
   Z : {
      1: [[1,1,0],
          [0,1,1]],
      2: [[0,1],
          [1,1],
          [1,0]],
      length: 2
   },
   I : {
      1: [[1],
          [1],
          [1],
          [1]],
      2: [[1,1,1,1]],
      length: 2
   },
   J : {
     1: [[1,0],
         [1,0],
         [1,1]],
     2: [[1,1,1],
         [1,0,0]],
     3: [[1,1],
              [0,1],
              [0,1]],
     length: 3
   },
   L : {
      1: [[0,1],
          [0,1],
          [1,1]],
      2: [[1,0,0],
          [1,1,1]],
      3: [[1,1],
          [1,0],
          [1,0]],
      length: 3
   },
   T : {
      1: [[0,1,0],
          [1,1,1]],
      2: [[1,0],
          [1,1]
          [1,0]],
      3: [[1,1,1],
          [0,1,0]],
      4: [[0,1],
          [1,1],
          [0,1]],
      length: 4
   },
   length: 7
};
var gameField = {};
gameField.block = [];
/**
 * Field block constructor
 * @param obj contains all needed options for block
 * @returns new gameField.block object
 */
var block = function(obj) {
   return {
      x: obj.x,
      y: obj.y,
      active: obj.active,
      start: obj.start,
      border: obj.border,
      element: obj.element
   };
};
/**
 * Create game field function
 * @param width
 * @param height
 */
var createField = function(width, height) {
   var y = height;
   var x = width;
   var container = document.createElement('div');
   container.setAttribute('id', 'container');
   container.style.height = (31 * y) + 'px';
   container.style.width = (31 * x) + 'px';
   gameField.sizeX = x;
   gameField.sizeY = y;
   for (var i = 0; i < y; i++) {
      gameField.block[i] = [];
      var fieldY = document.createElement('div');
      for (var j = 0; j < x; j++) {        
         var fieldX = document.createElement('div');
         fieldX.setAttribute('class', 'fieldBlock');
         fieldX.setAttribute('id', 'fbY-' + i + '_fbX-' + j);
         fieldY.appendChild(fieldX);
         /*if (j === 0) {
            fieldX.setAttribute('class', 'fieldBlockBorder');
            gameField.block[i][j] = block({
               x: j,
               y: i,
               active: 0,
               start: 0,
               border: 1,
               element: fieldX
            });
         } else if (j === x-1) {
            fieldX.setAttribute('class', 'fieldBlockBorder');
            gameField.block[i][j] = block({
               x: j,
               y: i,
               active: 0,
               start: 0,
               border: 1,
               element: fieldX
            });
         } else if (i === 0) {
            fieldX.setAttribute('class', 'fieldBlockBorder');
            gameField.block[i][j] = block({
               x: j,
               y: i,
               active: 0,
               start: 0,
               border: 1,
               element: fieldX
            });
         } else if (i === y-1) {
            fieldX.setAttribute('class', 'fieldBlockBorder');
            gameField.block[i][j] = block({
               x: j,
               y: i,
               active: 0,
               start: 0,
               border: 1,
               element: fieldX
            });
         } else */if (i === 1 && (j === Math.floor(x/2))) {
            gameField.block[i][j] = block({
               x: j,
               y: i,
               active: 0,
               start: 1,
               border: 0,
               element: fieldX
            });
            gameField.first = gameField.block[i][j]; 
         } else {
            gameField.block[i][j] = block({
               x: j,
               y: i,
               active: 0,
               start: 0,
               border: 0,
               element: fieldX
            });   
         }
      }
      container.appendChild(fieldY);
   }
   document.body.appendChild(container);
};